﻿namespace Reviewer.Web.UI
{
    using System;
    using System.Reflection;
    using AjaxControlToolkit.HTMLEditor;

    public class MetadataHtmlTextPropertyControl : MetadataPropertyControl
    {
        protected Editor htmlControl = new Editor();

        public MetadataHtmlTextPropertyControl(PropertyInfo property)
            : base(property)
        {
        }

        protected override void CreateChildControlsEx()
        {
            this.htmlControl.ID = this.ID + "_tb" + this.propertyInfo.Name;
            this.Controls.Add(this.htmlControl);

            this.label.AssociatedControlID = this.htmlControl.ID;
        }

        public override void Reset()
        {
            EnsureChildControls();
            this.htmlControl.Content = String.Empty;
        }

        public override void SetProperty(object item)
        {
            this.EnsureChildControls();

            this.propertyInfo.SetValue(item, this.htmlControl.Content, null);
        }

        public override void GetProperty(object item)
        {
            this.EnsureChildControls();

            this.htmlControl.Content = this.propertyInfo.GetValue(item, null).ToString();
        }

    }
}